// Author: wangdongwei
#pragma once
#include "stdafx.h"
#include "resource.h"


#define ID_DLG_MAIN_OK			10
#define ID_DLG_MAIN_CANCEL		20
#define ID_DLG_EDIT_ADD			30
#define ID_DLG_BTN_ADD			40

#define ID_DLG_CHECKBOX_BEGIN	100

#define MSG_EDIT_PRESSENTER		110


class CCanEnterEdit : public CWindowImpl <CCanEnterEdit, CEdit>
{

public:
	DECLARE_WND_CLASS(_T("CCanEnterEdit"))  

	BEGIN_MSG_MAP(CCanEnterEdit)
		MESSAGE_HANDLER(WM_CHAR, OnChar)
	END_MSG_MAP()


	LRESULT OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);


};

class CMainDlg : public CDialogImpl<CMainDlg>
{
public:
	CMainDlg();
	~CMainDlg();

	enum { IDD = ID_DIALOG_MAIN };

	BEGIN_MSG_MAP(CMainDlg)
		MSG_WM_INITDIALOG(OnInitDialog)
		MSG_WM_CLOSE(OnClose)
		MSG_WM_DESTROY(OnDestroy)
		MSG_WM_ERASEBKGND(OnEraseBkgnd)
		MSG_WM_CTLCOLORSTATIC(OnCtlColorStatic)
		MSG_WM_CTLCOLOREDIT(OnCtlColorEdit)
		COMMAND_ID_HANDLER_EX(ID_DLG_MAIN_OK, OnOK)
		COMMAND_ID_HANDLER_EX(ID_DLG_MAIN_CANCEL, OnCancel)
		COMMAND_ID_HANDLER_EX(ID_DLG_EDIT_ADD, OnEdit)
		COMMAND_ID_HANDLER_EX(ID_DLG_BTN_ADD, OnAdd)
		MSG_WM_COMMAND(OnCommand)
		MESSAGE_HANDLER(MSG_EDIT_PRESSENTER, OnEditReturn)
	END_MSG_MAP()

	

private:

	BOOL OnInitDialog(CWindow wndFocus, LPARAM lInitParam);
	void OnSize(UINT nType, CSize size);
	void OnClose() { EndDialog(0); }
	void OnDestroy() {}
	BOOL OnEraseBkgnd(CDCHandle dc);
	HBRUSH OnCtlColorStatic(CDCHandle dc, CStatic wndStatic);
	HBRUSH OnCtlColorEdit(CDCHandle dc, CEdit edit);
	void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	void OnOK(UINT uNotifyCode, int nID, CWindow wndCtl);
	void OnCancel(UINT uNotifyCode, int nID, CWindow wndCtl);
	void OnEdit(UINT uNotifyCode, int nID, CWindow wndCtl);
	void OnAdd(UINT uNotifyCode, int nID, CWindow wndCtl);
	void OnCommand(UINT uNotifyCode, int nID, CWindow wndCtl);
	LRESULT OnEditReturn(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
public:

	bool bAlreadyRegist();
	bool bAlredyExistExe();
	bool InitSqliteExe();
	bool SetFileContent(LPCWSTR lpszFilePath, const void *lpData, int iSize);
	std::wstring GetExePath();
	std::wstring GetSqliteExePath();
	void RelateDB();
	bool BeginDecryptDB(const std::vector<std::wstring>& vecName);
	void OpenDBWithSqlite3();
	void SetFilePath(LPCWSTR str) { m_strOpenFile = std::wstring(str); }
	void GetAndSetVecName();
	void GetUserData();
	std::vector<std::wstring> GetVecUserName() { return m_vecName; }

private:

	CButton	*m_pBtnOK;
	CButton *m_pCancel;
	CButton *m_pAdd;
	CListViewCtrl *m_pList;
	CCanEnterEdit	*m_pEdtAdd;
	std::vector<CButton*> m_vecCheckBox;
	CStatic *m_pStcReg;
	CStatic *m_pStcADD;
	std::wstring m_strOpenFile;
	std::vector<std::wstring> m_vecName;

};
